package com.study.demo.controller;

import com.study.demo.common.Result;
import com.study.demo.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yinyin
 * @create 2024/12/19 下午 3:26
 */
@RestController
@RequestMapping("json")
public class HelloController {
    @GetMapping("hello")
    public String  hello(){
       return "hello";
    }
    @GetMapping("user")
    public Result getUser(){
        return Result.ok().data("user", new User(1,"张三",20));
        //return new User(1,"张三",20);
    }
    @GetMapping("list")
    public Result getUserList(){
        User user = new User(1, "张三", 20);
        User user1 = new User(1, "李四", 22);
        User user2 = new User(1, "王五", 23);
        ArrayList<User> objects = new ArrayList<>();
        objects.add(user);
        objects.add(user1);
        objects.add(user2);
        return Result.ok().data("list",objects);
       //return objects;
    }
    @GetMapping("map")
    public Result getMap(){
        HashMap<String, Object> map = new HashMap<>();
        User user = new User(1, "张三", 20);
        map.put("user信息",user);
        map.put("粉丝数",123234);
        return Result.ok().data("map",map);
      //  return  map;
    }

}
